package com.invengo.module_check.ui.fragment.listing_by_car;

import static me.goldze.mvvmhabit.utils.constant.Constants.TOKEN_CAMERA;

import android.hardware.Camera;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.zxing.integration.android.IntentIntegrator;
import com.invengo.module_check.BR;
import com.invengo.module_check.R;
import com.invengo.module_check.databinding.FragmentListingByCarBinding;

import androidx.annotation.Nullable;
import me.goldze.mvvmhabit.base.BaseFragment;
import me.goldze.mvvmhabit.bus.Messenger;
import me.goldze.mvvmhabit.utils.ToastUtils;

public class ListingByCarFragment extends BaseFragment<FragmentListingByCarBinding,ListingByCarViewModel> {
    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_listing_by_car;
    }

    @Override
    public String getRightTitle() {
        return "扫书车";
    }

    @Override
    public void onRightEvent(View view) {
        if (cameraCount > 0)
            openCamera();
        else
            ToastUtils.showShort("该设备无相机，无法使用扫描功能！！");

    }

    private int cameraCount = 0;

    @Override
    public void initData() {
        cameraCount = Camera.getNumberOfCameras();
//        openCamera();
//        new IntentIntegrator(getActivity()).initiateScan();
//        IntentIntegrator integrator = IntentIntegrator.forSupportFragment(this);
    }



    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    private void openCamera(){
        IntentIntegrator integrator = new IntentIntegrator(getActivity());
        integrator.setOrientationLocked(true);
        integrator.initiateScan();
    }
}
